package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.SysUser;
import com.itheima.service.UserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/userrole")
public class UserRoleController {
    @Reference
    UserRoleService userRoleService;
    @RequestMapping("/add")
    public Result add(@RequestBody SysUser sysUser,Integer[] checkitemIds){
       userRoleService.add(sysUser,checkitemIds);
       log.debug("用户新增成功");
        return new Result(true,"新增用户成功");
    }
    @RequestMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=userRoleService.findPage(queryPageBean);
        log.debug("用户查询分页成功");
        return  new Result(true,MessageConst.QUERY_CHECKGROUP_SUCCESS,pageResult);
    }
    @RequestMapping("/delById")
    public Result delById(Integer id){
        userRoleService.delById(id);
        log.debug("用户删除成功");
        return new Result(true,"用户删除成功");
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        SysUser sysUser=userRoleService.findById(id);
        log.debug("根据id查询用户成功");
        return new Result(true,"根据id查询用户成功",sysUser);
    }
    @RequestMapping("/findRoleById")
    public Result findRoleById(Integer id){
        List<Integer>roleIds=userRoleService.findRoleById(id);
        log.debug("根据id查询角色类型成功");
        return new Result(true,"根据id查询角色类型成功",roleIds);
    }
    @RequestMapping("/edit")
    public  Result edit(Integer[] checkitemIds, @RequestBody SysUser sysUser){
        userRoleService.edit(sysUser,checkitemIds);
        log.debug("用户信息修改成功");
        return new Result(true,"用户信息修改成功");
    }
}
